<template>
  <div id="app">
    <p>我是app</p>
    <headervue @add="addlist"></headervue>
    <bodyvue @del="dellist" :listData="listData"></bodyvue>
    <footervue @clear="resetlist" :listData="listData"></footervue>
  </div>
</template>

<script>
import headervue from "../components/00/headerVue.vue";
import bodyvue from "../components/00/bodyVue.vue";
import footervue from "../components/00/footerVue.vue";
export default {
  name: "App",
  data() {
    return {
      listData: JSON.parse(localStorage.getItem("list")) || [
        { id: 1, name: "锻炼" },
        { id: 2, name: "开车" },
        { id: 3, name: "游戏" },
        { id: 4, name: "钓鱼" },
      ],
    };
  },
  components: {
    headervue,
    bodyvue,
    footervue,
  },
  methods: {
    dellist(value) {
      this.listData = this.listData.filter((item) => item.id != value);
    },
    addlist(value) {
      this.listData.unshift({
        id: +new Date(),
        name: value,
      });
    },
    resetlist() {
      this.listData = [];
    },
  },
  watch: {
    listData: {
      deep: true,
      handler(value) {
        localStorage.setItem("list", JSON.stringify(value));
      },
    },
  },
};
</script>

<style scoped>
#app {
  text-align: center;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
  padding: 30px;
  width: 400px;
  margin: 10px auto;
  background-color: #fff;
}
</style>
